#include <graphics/FontManager.h>

namespace ne
{
    template<> FontManager* Singleton<FontManager>::mpInstance = 0;

    FontManager::FontManager()
    {
        mResourceType = "Font";
        std::cout << "Construct Font Manager\n";
    }

    FontPtr FontManager::createFontFromTexture(Texture &texture, const uint32_t fontSize,
                                               const uint32_t width, const uint32_t height)
    {
        FontPtr pFont(create(texture.getName(), texture.getFileName(), true));
        pFont->createInternalFont(TexturePtr(&texture), FT_IMAGE, fontSize,
                                  width, height, FHT_NORMAL);
        pFont->load();
        return pFont;
    }

    FontPtr FontManager::createTrueTypeFont(const std::string &name,
                                            const std::string &fileName,
                                            const uint32_t fontSize,
                                            const FontHintType hint)
    {
        FontPtr pFont(create(name, fileName));
        pFont->createInternalFont(TexturePtr(), FT_TRUETYPE, fontSize,
                                  0, 0, hint);
        return pFont;
    }

    FontManager::~FontManager()
    {
        std::cout << "Disconstruct Font Manager\n";
    }

    FontManager& FontManager::GetSingleton()
    {
        assert(mpInstance);
        return *mpInstance;
    }

    FontManager* FontManager::GetSingletonPtr()
    {
        return mpInstance;
    }

    Resource* FontManager::createImplement(const uint64_t id,
                                           const std::string &name,
                                           const std::string &fileName,
                                           const bool isManual,
                                           ManualResourceLoader *pLoader)
    {
        return new Font(this, id, name, fileName, isManual, pLoader);
    }
}
